import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class Demo14 {
    public static void main(String[] args) {
        String driver;
        String url;
        String user;
        String password;
        InputStream resourceAsStream=Demo14.class.getClassLoader().getResourceAsStream("jdbc.properties");
        Properties properties=new Properties();
        try {
            properties.load(resourceAsStream);
            driver = properties.getProperty("driverClass");
            url = properties.getProperty("url");
            user = properties.getProperty("user");
            password = properties.getProperty("password");
        }catch(IOException e){
            throw new RuntimeException(e);
        }
        try{
            Class.forName(driver);
            Connection connection= DriverManager.getConnection(url,user,password);
            Statement statement=connection.createStatement();
            String sql="select id,name name,password pwd from demo";
            ResultSet resultSet=statement.executeQuery(sql);
            while(resultSet.next()){
                int id=resultSet.getInt("id");
                String username=resultSet.getNString("name");
                String pwd=resultSet.getNString("pwd");
                System.out.println(id+"\t"+username+"\t"+pwd+"\t");
            }
            resultSet.close();
            statement.close();
            connection.close();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}
